package TUILayer;//makes this class a part of the TUILayer package
import java.util.Scanner;
import ControlLayer.*;//The TUILayer needs to know the ControlLayer
/**
 * 
 * User interface - main menu
 * The entry-point for the application:
 * Create an instance of class MainMenuUI and the constructor starts the application
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * (FEN): 2006.02.24: Comments translated into English
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 *                    
 * (KBH): 2008.10.24: Change af manimenuStart to if
 */
public class MainMenuUI
{
    //the reference to the ControlLayer
    private AddressBookUI adrUI;//references to other UI objects
    private DvdUI dvdUI;
    private LoanUI loanUI;

    /**
     * Constructor of the MainMenuUI class.
     */
    public MainMenuUI()
    {
        adrUI= new AddressBookUI();
        dvdUI= new DvdUI();
        loanUI = new LoanUI();
    }

    /**
     * Refers to the writeMainMenu method and looks what choice is made.
     * If the choise is legal, it will proceed by starting the correct method.
     */
    public void mainMenuStart()
    {
        boolean exit=false;
        while (!exit) //! means while exit not is true (that is: false)
        {
            int choice = writeMainMenu();
            if(choice == 1)
            {
                startAddressBook();
            }
            else{
                if(choice == 2){ 
                    startDvd();
                }
                else{
                    if(choice == 3){
                        //start loanController 
                        startLoan();
                    }//end if
                    else{
                        writeEnd();
                        exit = true;
                    }
                }
                //end else
            }// end else
        }//end else
    }//end while

    /**
     * Creating a keyboard object to read input, and then printing out a TUI.
     * Here the user can enter a number 1-4 to indicate what he wishes to do.
     * 
     * @return          the input choise that has been entered.
     */
    private int writeMainMenu()
    {       
        // creates a keyboard object to read input
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** MainMenu ***");
        System.out.println(" (1) AddressBook");
        System.out.println(" (2) DVDs");
        System.out.println(" (3) Loan");
        System.out.println(" (4) Close");
        System.out.print("\n Make your choice: ");

        int choise = keyboard.nextInt();

        return choise;
    }

    /**
     * Crating a new AddressBookUI and calling the addressMenu method.
     */
    private void startAddressBook()
    {
        adrUI.addressMenu();
        //the adrUI needs to have a reference to the address controller
        //main controller can return references to the other controllers

    }

    /**
     * Creating a new DvdUI and calling the dvdMenu method.
     */
    private void startDvd()
    {
        dvdUI.dvdMenu();
        //the DvdUI needs to have a reference to the DVD controller
        //main controller can return references to the other controllers

    }

    /**
     * Creating a new LoanUI and calling the loanMenu method.
     */
    private void startLoan()
    {
        loanUI.loanMenu();

    }

    /**
     * Create test objects for Unit test.
     */
    public void UnitTestAddData()
    {
        adrUI.createDataset();
        dvdUI.createDataSet();
        loanUI.createDataSet();
    }

    /**
     * Printing out a sentence when the program is asked to shut down.
     */
    private void writeEnd()
    {
        System.out.println(" The Program have stopped.");
    }

}
